﻿namespace Way.Bus.WMS.ST.Controllers.YS
{
    using System;
    using Way.Bus.Controllers;
    using Way.Bus.WMS.ST.Model;
    using Way.Bus.Model;
    using Way.EAP.DataAccess.Regulation;
    using Way.EAP.DataAccess.Entity;
    using System.Collections.Generic;
    using Way.Contract.MVC;
    using Way.Contract.Data.ControllerData;
    /// <summary>
    /// 司机管理
    /// </summary>
    public class ST_CarController : BusinessBaseController
    {
        public ST_CarController()
            : base(new ST_CarList())
        {
        }
        /// <summary>
        /// 司机管理主单显示初始化
        /// </summary>
        /// <param name="data">主单</param>
        /// <param name="item">成员</param>
        public static void InitCarList(Way.Contract.Data.ModelData data, Way.Contract.Data.ItemData item)
        {
            data.title = "司机管理";
            item.visible = false;
            if (item.IsField("LoginName"))
            {
                item.visible = true;
                item.index = 1;
            }
            if (item.IsField("WorkName"))
            {
                item.title = "司机姓名";
                item.visible = true;
                item.index = 2;
            }
            if (item.IsField("PhoneCode"))
            {
                item.visible = true;
            }
            if (item.IsField("CarNo"))
            {
                item.visible = true;
            }
            if (item.IsField("CarType"))
            {
                item.visible = true;
            }
            if (item.IsField("IsDisable"))
            {
                item.visible = true;
                item.index = 5;
                item.required = true;
            }
        }
        protected override void OnInitViewChildItem(Way.Contract.Data.ModelData data, Way.Contract.Data.ItemData item)
        {
            if (data.name.EndsWith("Role"))
                data.visible = false;
            if (data.name.EndsWith("CarList"))
            {
                InitCarList(data, item);
            }
        }
        public override bool IsSubmit
        {
            get
            {
                return false;
            }
        }
        public override bool IsReviewedState
        {
            get
            {
                return false;
            }
        }
        public override bool IsImportIn
        {
            get
            {
                return false;
            }
        }
        protected override void OnAdding(Way.Contract.MVC.ControllerBase.SaveEvent item)
        {
            EntityList<OfficeWorker> list = new EntityList<OfficeWorker>(this.model.GetDataAction());
            list.GetData("LoginName='" + item.Item["LoginName"] + "'");
            if (list.Count > 0)
            {
                item.Breakoff = true;
                throw new Exception("登陆名已存在，不能重复，请更改后重试！");
            }
            base.OnAdding(item);
            if (item.Item is ST_CarList)
            {
                ((ST_CarList)item.Item).STAY5 = "司机";
                ((ST_CarList)item.Item).IsLoginUser = true;
                ((ST_CarList)item.Item).WorkPassWord = "123456";
            }
        }
        public static void SearchDriceWhere(List<SQLWhere> where)
        {
            SQLWhere w = new SQLWhere();
            w.ColumnName = "STAY5";
            w.Value = "司机";
            w.Relation = "and";
            where.Add(w);
        }
        protected override void OnGetWhereing(IModel m, List<SQLWhere> where,loadItem item)
        {
            base.OnGetWhereing(m, where, item);
            SearchDriceWhere(where);
        }
        protected override IEntityBase OnRemoveRuning()
        {
            return new ST_PackList();
        }
       
    }
}

